home *** CD-ROM | disk | FTP | other *** search
- // SimpleView.cpp : implementation of the CSimpleView class
- //
-
- #include "stdafx.h"
- #include "Simple.h"
-
- #include "SimpleDoc.h"
- #include "SimpleView.h"
- #include "ctwxdef.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CSimpleView
-
- IMPLEMENT_DYNCREATE(CSimpleView, CFormView)
-
- BEGIN_MESSAGE_MAP(CSimpleView, CFormView)
- //{{AFX_MSG_MAP(CSimpleView)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSimpleView construction/destruction
-
- CSimpleView::CSimpleView()
- : CFormView(CSimpleView::IDD)
- {
- //{{AFX_DATA_INIT(CSimpleView)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // TODO: add construction code here
-
- }
-
- CSimpleView::~CSimpleView()
- {
- }
-
- void CSimpleView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSimpleView)
- DDX_Control(pDX, IDC_SCROLLXCTRL1, m_RTScroll1);
- //}}AFX_DATA_MAP
- }
-
- BOOL CSimpleView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CFormView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CSimpleView printing
-
- BOOL CSimpleView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
-
- void CSimpleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
-
- void CSimpleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
-
- void CSimpleView::OnPrint(CDC* pDC, CPrintInfo*)
- {
- // TODO: add code to print the controls
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CSimpleView diagnostics
-
- #ifdef _DEBUG
- void CSimpleView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CSimpleView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
-
- CSimpleDoc* CSimpleView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSimpleDoc)));
- return (CSimpleDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CSimpleView message handlers
-
- BEGIN_EVENTSINK_MAP(CSimpleView, CFormView)
- //{{AFX_EVENTSINK_MAP(CSimpleView)
- ON_EVENT(CSimpleView, IDC_SCROLLXCTRL1, 1 /* OnInternalTimer */, OnInternalTimerScrollxctrl1, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CSimpleView::OnInternalTimerScrollxctrl1()
- {
-
- double rData[16];
- int i;
- static double rLastData[16];
- static BOOL bFirstDemoPass = FALSE;
-
- double rMin = min( m_RTScroll1.GetAxisMin (Y_AXIS1), m_RTScroll1.GetAxisMax (Y_AXIS1));
- double rMax = max( m_RTScroll1.GetAxisMin (Y_AXIS1), m_RTScroll1.GetAxisMax (Y_AXIS1));
- double rCenter = (rMax - rMin) /2;
- double rRange = (rMin - rMax);
-
- for (i=0; i < m_RTScroll1.GetSDataNumGroups (0); i++)
- {
- if (!bFirstDemoPass)
- rData[i] = rCenter + rRange * 1.0 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
- else
- rData[i] = rLastData[i] + rRange * 0.2 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
-
- if (rData[i] > rMax)
- rData[i] = rMax;
- else
- if (rData[i] < rMin)
- rData[i] = rMin;
- rLastData[i] = rData[i];
- }
-
- bFirstDemoPass = TRUE;
- m_RTScroll1.UpdateDynData (0, rData);
-
- }
-
- void CSimpleView::BuildGraph1()
- {
- m_RTScroll1.SetSDataEnable (0, TRUE); // enable the 1st data set
- m_RTScroll1.SetSPlotType (0, SCROLLING_LINE_GRAPH);
- m_RTScroll1.SetSDataNumGroups (0, 4); // four channels of data
-
- //axis
- m_RTScroll1.SetAxisMax (X_AXIS1, 25.0); // x axis from 0 - 25
- m_RTScroll1.SetAxisEnable (X_AXIS2, TRUE); //enable the second x axis
- m_RTScroll1.SetAxisEnable (Y_AXIS2, TRUE); //enable the second x axis
- m_RTScroll1.SetAxisMajorTickInterval (X_AXIS1, 5.0); //label every 5 units
-
- //alarm updating
- m_RTScroll1.SetScrollAlarmMarksEnable (0, TRUE); //enable alarm marks
- m_RTScroll1.SetScrollLowAlarmEnable (0, TRUE); //enable lo alarm line
- m_RTScroll1.SetScrollHighAlarmEnable (0, TRUE); //enable hi alarm line
- m_RTScroll1.SetScrollSetpointEnable (0, TRUE); //enable set point line
-
- //title
- m_RTScroll1.SetTitleString (TITLE1,"Scroll Graph"); //graph title
-
- //window
- m_RTScroll1.SetWindowBackgroundColor (C_PALEBLUE); //background color
- m_RTScroll1.SetWindowBorderStyle (RC_HIGH);
-
- //use internal timer
- m_RTScroll1.SetEnableInternalTimer(TRUE);
-
- }
-
- void CSimpleView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- BuildGraph1();
- }
-